package cn.qingfeng.a005_rpc.server.handler;

import cn.qingfeng.a005_rpc.message.RpcResponseMessage;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.Promise;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@ChannelHandler.Sharable
public class RpcResponseMessageHandler extends SimpleChannelInboundHandler<RpcResponseMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RpcResponseMessage msg) throws Exception {
        log.debug("{}", msg);
        Object returnValue = msg.getReturnValue();
        Exception exceptionValue = msg.getExceptionValue();
        if (exceptionValue != null) {
            log.error("调用方法异常：" + exceptionValue);
        } else {
            log.info("调用方法返回值：" + returnValue);
        }
    }
}
